package com.wk1un2.controller;

import java.util.Date;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.wk1un2.service.TeachersService;
import com.wk1un2.util.Result;

@RestController
public class TeachersController {
	@Autowired
	private TeachersService teachersservice;

	@RequestMapping("/getAllTeachers")
	public Object getAll(@RequestParam Map<String, Object> map) {
		Integer page = Integer.parseInt(map.get("page").toString());
		Integer limit = Integer.parseInt(map.get("limit").toString());
		map.put("page", (page - 1) * limit);
		map.put("limit", limit);
		Result res = new Result(0, "", teachersservice.count(map), teachersservice.getAll(map));
		return res;
	}

	@RequestMapping("/addTeachers")
	public Object add(@RequestParam Map<String, Object> map) {
		map.put("t_card", new Date().getTime());
		Result res = new Result(0, "", teachersservice.add(map), true);
		return res;
	}

	@RequestMapping("/updateTeachers")
	public Object update(@RequestParam Map<String, Object> map) {
		map.put("t_card", new Date().getTime());
		Result res = new Result(0, "", teachersservice.update(map), true);
		return res;
	}

	@RequestMapping("/deleteTeachers")
	public Object delete(Integer t_id) {
		Result res = new Result(0, "", teachersservice.delete(t_id), true);
		return res;
	}
}
